﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.WebControls;

namespace SilverlightViewer.WebPart
{
    [ToolboxItemAttribute(false)]
    public class SLHost : System.Web.UI.WebControls.WebParts.WebPart
    {
        [Personalizable(), WebBrowsable, WebDisplayName("File location"), Category("Silverlight Settings")]
        public string SlViewer { get; set; }


        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/SilverlightViewer/slviewer/VisualWebPart1UserControl.ascx";

        protected override void CreateChildControls()
        {
            Control control = Page.LoadControl(_ascxPath);
            if (control != null)
            {
                if (SlViewer != "")
                {
                    SilverlightViewer viewer = control as SilverlightViewer;
                    viewer.silverlightLocation = this.SlViewer;
                    viewer.width = this.Width.Value - 10.0;
                    viewer.height = this.Height.Value - 10.0;
                    Controls.Add(viewer);
                }
                else
                {
                    Controls.Add(new LiteralControl("Please specify a silverlight .xap location in the tool pane."));
                }
            }
        }
    }
}
